package homework05;

import java.util.concurrent.Callable;

public class CountPrimePerPart implements Callable<Integer> {

	int left, right;

	public CountPrimePerPart(int lower, int upper) {
		this.left = lower;
		this.right = upper;
	}

	@Override
	public Integer call() {
		int total = 0;
		for (int i = left; i <= right; i++)
			if (isPrime(i)) {
				System.out.println(i);
				total++;
			}
		return total;
	}

	public boolean isPrime(final int number) {
		if (number <= 1)
			return false;
		for (int i = 2; i <= Math.sqrt(number); i++)
			if (number % i == 0)
				return false;
		return true;
	}
}
